package com.cn.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.connector.Request;

import com.cn.domain.News;
import com.cn.service.NewsService;
import com.cn.service.impl.NewsServiceImpl;
import com.cn.utils.JsonMapper;


@WebServlet(value="/NewsServlet")
public class NewsServlet extends HttpServlet {
	private NewsService newsService=new NewsServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//根据id显示当前点击的新闻
		resp.setContentType("text/html;charset=utf-8");
		req.setCharacterEncoding("utf-8");
		String id=req.getParameter("nid");
		
		//req.setAttribute("news",newsService.queryAllNews());
		
		if(id!=null){
			News news=newsService.queryNewsById(id);
			if(news!=null){
				req.setAttribute("newss",news);
				req.getRequestDispatcher("/news_view.jsp").forward(req, resp);
			}else{
				//没有该新闻，无需操作
			}
		}
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
